package com.lms.logistics_management_system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lms.logistics_management_system.controller.dto.HistoryDiagnostic;
import com.lms.logistics_management_system.entity.Item;
import com.lms.logistics_management_system.entity.QueueCondition;
import com.lms.logistics_management_system.entity.Reservation;
import com.lms.logistics_management_system.entity.ReservationItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ItemMapper extends BaseMapper<Item> {

    @Select("SELECT DISTINCT r.reservation_id,MIN(ri.reservation_item_result_comeout) as reservation_item_result_comeout,r.reservation_name,MAX(dia.diagnostic_create_time) as diagnostic_create_time \n" +
            "FROM reservation r\n" +
            "JOIN reservation_item ri ON r.reservation_id=ri.reservation_id\n" +
            "WHERE opend_id=#{openId} AND reservation_item_result_comeout==0\n" +
            "GROUP BY reservation_id\n" +
            "ORDER BY item_id DESC;")
    List<Reservation> getUnfinishedResByOpenid(String opneId);





//    SELECT * FROM reservation r
//    JOIN reservation_item ri ON r.reservation_id=ri.reservation_id
//    WHERE  r.reservation_id not in
//            (SELECT reservation_id from reservation_item where reservation_item_result_comeout=0 )
//    GROUP BY r.reservation_id
//    ORDER BY item_id DESC;

    @Select("SELECT department_id FROM item WHERE item_id=#{itemId}")
    Integer getDepartmentId(Integer itemId);

    @Select("SELECT item_name FROM item WHERE item_id=#{itemId}")
    Integer getItemName(Integer itemId);

    @Select("SELECT item_name like '王%' order by age desc,id asc")
    Integer queryItem(Integer itemId);



}

